package day240424.work;

import java.util.Random;
import java.util.Scanner;

public class Rock {
    public static void main(String[] args) {
        // get user input
        String userInput;
        Scanner input = new Scanner(System.in);
        while (true) {
            System.out.println("Enter rock, paper or scissors:");
            userInput = input.nextLine();
            userInput = userInput.toLowerCase();

            if (userInput.equals("rock") || userInput.equals("paper") || userInput.equals("scissors")) {
                break;
            }
        }

        // get computers choice
        String computerChoice;
        int randomNumber = (int) (Math.random() * 3) + 1;

        if (randomNumber == 1) {
            computerChoice = "rock";
        } else if (randomNumber == 2) {
            computerChoice = "paper";
        } else {
            computerChoice = "scissors";
        }

        // get results: "win", "lose" or "draw"
        String result;
        // condition for user to draw
        if (userInput.equals(computerChoice)) {
            result = "draw";
        }

        // condition for user to win
        else if (userInput.equals("paper") && computerChoice.equals("rock")) {
            result = "win";
        } else if (userInput.equals("rock") && computerChoice.equals("scissors")) {
            result = "win";
        } else if (userInput.equals("scissors") && computerChoice.equals("paper")) {
            result = "win";
        }
        // all other conditions result to loss
        else {
            result = "lose";
        }

        System.out.println("User Input: " + userInput);
        System.out.println("Computer Choice: " + computerChoice);
        System.out.println(result);
    }


}

